__author__='kiana'
#coding=utf-8
import sympy as sym
from ttg import Truths

def is_tautology(expression):
    symbols = sym.sympify(expression).free_symbols
    symbol_str = ', '.join(map(str, symbols))
    tt = Truths([symbol_str, expression])
    return all(row[-1] for row in tt.as_pandas().itertuples(index=False))

# 定义符号 p,q
p, q = sym.symbols('p q')

# 输出析取三段论，中间逗号使用析取符号
result = f"{p} ∨ {q}, {q} ∨ {p}"
print(result)

# 判断((p -> q) & q) -> p 是否为重言式
formula = "((p >> q) & q) >> p"
tautology_result = is_tautology(formula)
print(tautology_result)

# 验证析取三段论是否为重言式
example_formula = "(p | q) & (q | p)"
example_result = is_tautology(example_formula)
print(example_result)
